function the_top() {
    window.scrollTo(0, 0);
}

//rem手机适配
new function () {
    var _self = this;
    _self.width = 640;//设置默认最大宽度
    _self.fontSize = 100;//默认字体大小
    _self.widthProportion = function () {
        var p = (document.body && document.body.clientWidth || document.getElementsByTagName("html")[0].offsetWidth) / _self.width;
        return p > 1 ? 1 : p < 0.5 ? 0.5 : p;
    };
    _self.changePage = function () {
        document.getElementsByTagName("html")[0].setAttribute("style", "font-size:" + _self.widthProportion() * _self.fontSize + "px !important");
    }
    _self.changePage();
    window.addEventListener('resize', function () {
        _self.changePage();
    }, false);
};

//输入框提示不同内容
function input_alert(html, time) {
    if (!time) {
        time = 2000;
    }
    var float_element = $(".c-float-popWrap")
    var hei = $(window).height() / 2
    var top = $(document).scrollTop() + hei - 30;
    float_element.css({"top": top + "px"})
    $(".warnMsg").html(html)
    float_element.show()
    setTimeout(function () {
        float_element.hide()
    }, time);

}
//轮播
/*function slid(slid) {
    var _SlideshowTransitions = [
        {
            $Duration: 500,
            x: -0.3,
            $During: {$Left: [0.3, 0.7]},
            $Easing: {$Left: $JssorEasing$.$EaseInCubic, $Opacity: $JssorEasing$.$EaseLinear},
            $Opacity: 1
        }

    ];
    var options = {
        $AutoPlay: true,
        $AutoPlayInterval: 3000,
        $PauseOnHover: 1,
        $DragOrientation: 1,
        $ArrowKeyNavigation: true,
        $SlideDuration: 500,
        $SlideshowOptions: {
            $Class: $JssorSlideshowRunner$,
            $Transitions: _SlideshowTransitions,
            $TransitionsOrder: 1,
            $ShowLink: true
        },

        $ThumbnailNavigatorOptions: {
            $Class: $JssorThumbnailNavigator$,
            $ChanceToShow: 2,
            $ActionMode: 1,
            $SpacingX: 5,
            $DisplayPieces: 100,
            $ParkingPosition: 360
        }
    };

    var jssor_slider1 = new $JssorSlider$(slid, options);

    function ScaleSlider() {
        var parentWidth = jssor_slider1.$Elmt.parentNode.clientWidth;
        if (parentWidth)
            jssor_slider1.$ScaleWidth(Math.max(Math.min(parentWidth, 800), 300));
        else
            window.setTimeout(ScaleSlider, 300);
    }

    ScaleSlider();
    $(window).bind("load", ScaleSlider);
    $(window).bind("resize", ScaleSlider);
    $(window).bind("orientationchange", ScaleSlider);
};*/
/*底部按钮切换*/
function EnterChange(x) {
    if (x == 1) {
        document.getElementById("img1").src = "images/menu-2.png"
        document.getElementById("img2").src = "images/me-1.png"
        document.getElementById("img3").src = "images/cart-1.png"
        $("#change1").find("span").addClass("bot_focus");
        $("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
    } else if (x == 2) {
        document.getElementById("img1").src = "images/menu-1.png"
        document.getElementById("img2").src = "images/me-2.png"
        document.getElementById("img3").src = "images/cart-1.png"
        $("#change1").find("span").removeClass("bot_focus");
        $("#change2").find("span").addClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
    } else if (x == 3) {
        document.getElementById("img1").src = "images/menu-1.png"
        document.getElementById("img2").src = "images/me-1.png"
        document.getElementById("img3").src = "images/cart-2.png"
        $("#change1").find("span").removeClass("bot_focus");
        $("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").addClass("bot_focus");
    } else if (x == 4) {
        document.getElementById("img1").src = "images/menu-1.png"
        document.getElementById("img2").src = "images/me-1.png"
        document.getElementById("img3").src = "images/cart-1.png"
        $("#change1").find("span").removeClass("bot_focus");
        $("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
    }
}
/*搜索栏滚动状态改变函数*/
function scoll_color() {
    var start = {
        starty: 0,
        startx: 0,
        scrolly: 0,
    };
    var divheight = window.document.getElementById("slider").offsetHeight;
    var searchHeight = $(".ngb-search-box").height();
    if(divheight == 0){
        setTimeout(function() {
            scoll_color();
        },500);
    }else{
        var initialOpacity = 0, mostOpacity = 0.85, showTop = 200;
        $(document).bind("touchstart", function () {
            var touches = event.touches[0];
            start.starty = touches.clientY;
            start.startx = touches.clientX;
            start.scrolly = 0;
        });
        $(document).bind("touchmove", function () {
            var touches = event.touches[0];
            var starty = touches.clientY;
            var startx = touches.clientX;
            var scrollTop = $(window).scrollTop();
            if (scrollTop < 0) {
                return
            }
            if (Math.abs(start.diry) <= Math.abs(start.dirx)) {
                var direct = 0;
                return
            }
            //判断是否和上次滚动方向相同
            start.scrolly = starty - start.starty;
            if (start.scrolly < 0) {
                changeOpacity(scrollTop + Math.abs(start.scrolly))
                goTop(scrollTop + Math.abs(start.scrolly))
            } else {
                changeOpacity(scrollTop - Math.abs(start.scrolly))
                goTop(scrollTop - Math.abs(start.scrolly))
            }
            start.starty = starty;
            start.startx = startx;
        });
        /*$(document).bind("touchend", function () {
            var scrollTop = $(window).scrollTop();
            getLastScrollPosition(scrollTop);
        });*/
        $(window).scroll(function () {
            var scrollTop = $(window).scrollTop();
            changeOpacity(scrollTop)
        })
        function changeOpacity(scrollTop) {
            if (scrollTop > (divheight - searchHeight)) {
                $('.search_ngb_top_abs').css("opacity", mostOpacity);
                return
            }
            if (scrollTop <= (divheight - searchHeight)) {
                $('.search_ngb_top_abs').css("opacity", scrollTop < searchHeight ? initialOpacity : mostOpacity * ((scrollTop - searchHeight) / (divheight - searchHeight)));
            } else {
                $('.search_ngb_top_abs').css("opacity", mostOpacity);
            }
        };
        /*function getLastScrollPosition(scrollTop){
            changeOpacity(scrollTop)
            var scrollTopNow;
            setTimeout(function(){
                scrollTopNow = $(window).scrollTop();
                console.log(scrollTop);
                console.log(scrollTopNow);
                if(scrollTopNow != scrollTop){
                    getLastScrollPosition(scrollTopNow);
                }else {
                    changeOpacity(scrollTopNow);
                }
            },50);
        }*/
        function goTop(scrollTop) {
            if (scrollTop >= showTop) {
                $("#go-top").css({"display": "block"});
            } else {
                $("#go-top").css({"display": "none"});
            }
        }

        $("#go-top").click(function () {
            window.scrollTo(0, 0);
            goTop(0)
        })
    }
}
//点击搜索框隐藏
function clickchange() {
    $(".search_ngb_mid").focus(function () {
        $(".model_btn").hide();
        $(".homepage").hide();
        $(".seekitem").fadeIn();
        $(".seekbox").focus();
    })
};
function clickback() {
    $(".seekitem").hide();
    $(".homepage").fadeIn();
    $(".model_btn").fadeIn();
    scoll_color();
}
//搜索栏监听事件
function search_top() {
    var t = 0, p = 0, change = $(window).height();
    var style = 1;
    if (style == 1) {
        $("#recommendList1").show();
        $("#recommendList2").hide();
    }
    window.onscroll = function () {
        t = document.documentElement.scrollTop || document.body.scrollTop;
        var seektop = document.getElementById("search_top");
        var scrollTop = $(window).scrollTop();
        if (scrollTop > change) {
            if (t > p) {
                $("#search_top").css({"transform": "translateY(-40px)"})
            }
            else {
                $("#search_top").css({"transform": "translateY(0px)"})
            }
            setTimeout(function () {
                p = t;
            }, 0)
        }
        goTop(scrollTop)
    };
    function goTop(scrollTop) {
        if (scrollTop >= change) {
            $("#go-top").css({"display": "block"});
        } else {
            $("#go-top").css({"display": "none"});
        }
    };
    $("#go-top").click(function () {
        $("#search_top").css({"transform": "translateY(0px)"})
        window.scrollTo(0, 0);
    })
    $("#change-style").click(function () {
        if (style == 1) {
            $("#recommendList1").hide();
            $("#recommendList2").show();
            $(".change-style").css({
                "background": "url(\"http://114.55.90.31/ngbimage/20161117style1.png\") no-repeat",
                "background-size": "100%"
            })
            style = 2;
        } else {
            $("#recommendList1").show();
            $("#recommendList2").hide();
            $(".change-style").css({
                "background": "url(\"http://114.55.90.31/ngbimage/20161117style2.png\") no-repeat",
                "background-size": "100%"
            })
            style = 1;
        }
    })
}


